# -*- coding:utf-8 -*-
import ctypes
import threading
import MySQLdb
import os
import socket
import json
import httplib
import urllib2
import uuid
import zipfile
import base64
import sys
import hashlib
import datetime
import time
import subprocess


def get_process_count(imagename):
    p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename) 
    return p.read().count(imagename) 

arr     = ['7001:A:F','7001:G:K','7001:L:S','7001:T:Z',
           '7002:A:F','7002:G:K','7002:L:S','7002:T:Z',
           '7003:A:F','7003:G:K','7003:L:S','7003:T:Z',
           '7004:A:F','7004:G:K','7004:L:S','7004:T:Z',
           '7005:A:F','7005:G:K','7005:L:S','7005:T:Z',
           '7006:A:F','7006:G:K','7006:L:S','7006:T:Z',
           '7007:A:F','7007:G:K','7007:L:S','7007:T:Z',
           '7008:A:F','7008:G:K','7008:L:S','7008:T:Z',
           '7009:A:F','7009:G:K','7009:L:S','7009:T:Z',
           '7010:A:F','7010:G:K','7010:L:S','7010:T:Z',
           '7011:A:F','7011:G:K','7011:L:S','7011:T:Z',
           '7012:A:F','7012:G:K','7012:L:S','7012:T:Z',
           '7013:A:F','7013:G:K','7013:L:S','7013:T:Z',
           '7014:A:F','7014:G:K','7014:L:S','7014:T:Z',
           '7015:A:F','7015:G:K','7015:L:S','7015:T:Z',
           '7016:A:F','7016:G:K','7016:L:S','7016:T:Z',
           '7017:A:F','7017:G:K','7017:L:S','7017:T:Z',
           '7018:A:F','7018:G:K','7018:L:S','7018:T:Z',
           '7019:A:F','7019:G:K','7019:L:S','7019:T:Z']
count   = 0
total_p = 18


# 非热门app 下载

while True:
    php_count = get_process_count('php.exe')
    print(php_count)
    if  php_count < total_p:
        if count >= len(arr):
            break
        print (str(arr[count])+'====' + str(count))

        p = subprocess.Popen("php E:/app_up/appupdate_info.php "+str(arr[count])+"")
        count += 1
        time.sleep(1)
    else:
        while True:
            if get_process_count('php.exe') < total_p:
                break
            time.sleep(100)
    if count >= len(arr):
        print("python Over\n")
        break